import { createRouter, createWebHashHistory } from "vue-router"; // 导入 Vue Router 中的创建路由实例和哈希历史模式的函数

// routes
const routes = [
    {
        redirect: "/home", // 当访问根路径时重定向到 "/home"
        path: "/"
    },
    // 首页路由
    {
        path: '/home', // 路径为 "/home"
        name: "home", // 路由名称
        component: () => import("@/view/home/index.vue") // 懒加载首页组件
    },
    // auth
    {
        path: '/auth',
        redirect: "/auth/login",
        children: [
            {
                path: 'login',
                component: () => import("@/view/auth/login.vue")
            },

            {
                path: 'reg',
                component: () => import("@/view/auth/reg.vue")
            },

            {
                path: 'forgetPassword',
                component: () => import("@/view/auth/forgetPassword.vue"),
                name: 'forgetPassword'
            },
        ]
    },
    {
        path: '/manage',
        component: () => import('@/view/manage/index.vue'),
        name: "管理页",
        children: [
            // ---------- 机构负责人 ----------
            // 机构菜单路由
            {
                path: 'organizationinfo',
                name: "manage-organizationinfo",
                component: () => import('@/view/manage/menusubassembly/organizationinfo.vue'),
                meta: {
                    index: "manage-organizationinfo",
                }
            },
            // 人员管理路由
            {
                path: 'personnel',
                name: "manage-personnel",
                component: () => import('@/view/manage/menusubassembly/personnel.vue'),
                meta: {
                    index: "manage-personnel",
                }
            },
            // 报名管理路由
            {

                path: 'registration',
                name: "manage-registration",
                component: () => import('@/view/manage/menusubassembly/registration.vue'),
                meta: {
                    index: "manage-registration",
                }
            },
            // 报名管理
            {
                path: 'registration/details/:eventId', // registration/details/123456
                name: "manage-registration-details",
                component: () => import('@/view/manage/menusubassembly/registration/details.vue'),
                meta: {
                    index: "manage-registration",
                }
            },
            // ID码获取
            {
                path: 'IDCodeAcquisition',
                name: "manage-IDCodeAcquisition",
                component: () => import('@/view/manage/agentmenu/idcode.vue'),
                meta: {
                    index: "manage-IDCodeAcquisition",
                }
            },
            // ---------- 组委会负责人 ----------
            // 组委会信息管理
            {
                path: 'committee',
                name: "manage-committee",
                component: () => import('@/view/manage/agentmenu/committee.vue'),
                meta: {
                    index: "manage-committee",
                }
            },
            // 机构管理
            {
                path: 'agents',
                name: "manage-agents",
                component: () => import('@/view/manage/agentmenu/agents.vue'),
                meta: {
                    index: "manage-agents",
                }
            },
            /**
            * 参赛审核
            */
            {
                path: 'organization',
                name: "manage-organization",
                component: () => import('@/view/manage/agentmenu/organization.vue'),
                meta: {
                    index: "manage-organization",
                }
            },
            // 统计与报表路由
            {
                path: 'statisticstements',
                name: "manage-statisticstements",
                component: () => import('@/view/manage/agentmenu/statisticstements.vue'),
                meta: {
                    index: "manage-statisticstements",
                }
            },
        ]
    },
    {
        path: '/test/echarts',
        component: () => import("@/view/test/echarts.vue")
    },
    // 对于所有未定义的路径,自动匹配404页面
    {
        path: '/:pathMatch(.*)*', component: () => import("@/view/404.vue")
    },
]

// 创建路由实例
const router = createRouter({
    history: createWebHashHistory(), // 使用哈希模式的浏览历史
    routes // 路由配置
});
// const LOGIN_ROUTERS = "manage"

// router.beforeEach((to, from, next) => {
//     if (to.fullPath.indexOf(LOGIN_ROUTERS) != -1) {
//         let token = localStorage.getItem("token")
//         if (!token) {
//             return next("/auth/login");
//         }
//     }
//     return next(true)
// })

export default router; // 导出路由实例